{% extends "base.html" %}

{% block pageheader %}Add CNAME record for {{ form.originating_record.value }}.{{ form.zone_name.value }}{% endblock pageheader %}

{% block body %}
<form class="form-horizontal" action="{% url "add_cname" dns_server=dns_server zone_name=form.zone_name.value record_name=originating_record %}" method="post">{% csrf_token %}
  <legend>Create CNAME record</legend>

  <div class="form-group{% if form.dns_server.errors %} has-error{% endif %}">
    <label for="dns_server" class="col-sm-3 control-label">DNS Server:</label>
    <div class="col-sm-5 col-md-4">
      <input id="dns_server" name="dns_server" type="text" class="form-control" value="{{dns_server.hostname}}" readonly="readonly" />
    </div>
    {% if form.dns_server.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.dns_server.errors|stringformat:"s"|striptags }}
        {% if form.dns_server.value %} Previous Value: {{ form.dns_server.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.originating_record.errors %} has-error{% endif %}">
    <label for="originating_record" class="col-sm-3 control-label">Originating Record: </label>
    <div class="col-sm-5 col-md-4">
      <input type="text" id="originating_record" name="originating_record" class="form-control" value="{{ form.originating_record.value }}" readonly="readonly"/>
    </div>
    {% if form.originating_record.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.originating_record.errors|stringformat:"s"|striptags }}
        {% if form.originating_record.value %} Previous Value: {{ form.originating_record.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.cname.errors %} has-error{% endif %}">
    <label for="cname" class="col-sm-3 control-label">CNAME: </label>
    <div class="col-sm-5 col-md-4">
      <div class="input-group">
        <input id="cname" name="cname" type="text" class="form-control"{% if form.cname.value %} value="{{ form.cname.value }}"{% endif %}/>
        <span class="input-group-addon">.{{ form.zone_name.value }}</span>
        <input type="hidden" name="zone_name" value="{{ form.zone_name.value }}"/>
      </div>
    </div>
    {% if form.cname.errors  %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.cname.errors|stringformat:"s"|striptags }}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.ttl.errors %} has-error{% endif %}">
    <label for="ttl" class="col-sm-3 control-label">TTL: </label>
    <div class="col-sm-5 col-md-4">
      <select id="ttl" name="ttl" class="form-control">
        {% for choice in form.ttl %}
        {{choice}}
        {% endfor %}
      </select>
    </div>
    {% if form.ttl.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.ttl.errors|stringformat:"s"|striptags }}
        {% if form.ttl.value %} Previous choice: {{ form.ttl.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group{% if form.key_name.errors %} has-error{% endif %}">
    <label for="key_name" class="col-sm-3 control-label">TSIG Key:</label>
    <div class="col-sm-5 col-md-4">
      <select id="key_name" name="key_name" class="form-control">
        {% for choice in form.key_name %}
          {{ choice }}
        {% endfor %}}
      </select>
    </div>
    {% if form.key_name.errors %}
    <div class="col-sm-4 col-md-5">
      <div class="alert alert-danger">
        {{ form.key_name.errors|stringformat:"s"|striptags }}
        {% if form.key_name.value %} Previous choice: {{ form.key_name.value }}{% endif %}
      </div>
    </div>
    {% endif %}
  </div>

  <div class="form-group">
    <div class="col-sm-3"></div>
    <div class="col-sm-5 col-md-4">
      <button type="submit" class="btn btn-default">Save Changes</button>
      <a href="{% url "zone_list" dns_server=dns_server zone_name=form.zone_name.value %}" class="btn btn-warning">Cancel</a>
    </div>
  </div>
</form>
{% endblock body %}
